package com.hyg.hometown.model;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "users")
public class User implements Serializable {
    @Id
    private String id;
    //名字
    @Column(name = "username",unique=true)
    private String username;
    //密码
    @Column(name = "password")
    private String password;
    //年龄
    @Column(name = "age")
    private String age;
    //盐值
    @Column(name = "salt")
    private String salt;
    //地址
    @Column(name = "address")
    private String address;
    //电话
    @Column(name = "phone")
    private String phone;
    //备注
    @Column(name = "remake")
    private String remake;
    @OneToMany(fetch = FetchType.EAGER)//立即加载
    @JoinTable(name = "user_role_relation",joinColumns = {@JoinColumn(name = "userid")},inverseJoinColumns = {@JoinColumn(name = "roleid")})
    private List<Role> roleList;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRemake() {
        return remake;
    }

    public void setRemake(String remake) {
        this.remake = remake;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    /**
     * 密码盐.
     * @return
     */
    public String getCredentialsSalt(){
        return this.username+this.salt;
    }


}
